<style type="text/css">
	.content{margin:20px;}
	
	.cloud-card{border-radius: 4px}
</style>
<div class="content cloud-card">
	<form class="layui-form layui-form-pane" action="" >
		<div class="layui-form-item">
			<label class="layui-form-label">旧密码</label>
			<div class="layui-input-block">
				<input type="password" class="layui-input" lay-verify="required|pass" placeholder="旧密码" name="old_password">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-block">
				<input type="password" class="layui-input" lay-verify="required|pass" placeholder="大于6位小于18位" name="new_password">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-block">
				<input type="password" class="layui-input" lay-verify="required|pass" placeholder="再输一次新密码" name="once_password">
			</div>
		</div>

		<div class="layui-form-item">
			<!-- <label class="layui-form-label"></label> -->
			<div class="layui-input-block">
				<div class="layui-btn" lay-submit lay-filter="update" >确定</div>
			</div>
		</div>
		
	</form>
</div>
<script type="text/javascript">
	layui.use(['table','form'],function(){
		var table=layui.table,$=layui.$;
		layui.form.on('submit(update)', function(data){
		 	console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
		 	console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
		 	console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
		 	if(data.field.new_password!==data.field.once_password){
		 		layer.msg('两次新密码输入不一致')
		 		return;
		 	}

		 	app.ajaxPost('/api/user/updatePassword',data.field,function(d){
		 		if(d.err_code==0){
		 			layer.alert('密码修改成功，将退出登录');
		 		}else{
		 			layer.msg('修改失败，'+d.err_msg)
		 		}
		 	})


		 	return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});

		layui.form.verify({
		   pass :[
			    /^[\S]{6,18}$/
			    ,'密码必须6到18位，且不能出现空格'
			  ]
		});  
		
		
	})
</script>